package com.awspaas.user.apps.cpq.job;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.schedule.IJob;
import com.actionsoft.sdk.local.SDK;
import com.alibaba.fastjson.JSONObject;
import com.awspaas.user.apps.cpq.util.RefreshDataUtils;
import com.awspaas.user.apps.cpq.util.RefreshModulDataUtils;
import com.awspaas.user.apps.cpq.util.RefreshTempDataUtils;

public class UpdateProductionJob implements IJob{

	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		try {
			/**
			 * 更新工资价格维护表
			 */
			List<BO>bos=SDK.getBOAPI().query("BO_EU_CPQ_PRODUCTION_PROCESS").addQuery("SFTJ=","1").list();
			if(bos.size()>0) {
				 String bms = "";
					List<String> bhList = new ArrayList<>();
					Map<String, JSONObject> userMap = new HashMap<String, JSONObject>();
				for (BO bo : bos) {
					String bm =  bo.getString("BM");
					JSONObject json = new JSONObject();
					json.put("PRICE", bo.getString("PRICE"));
					json.put("BM", bm);
					bhList.add(bm);
					userMap.put(bm, json);
					SDK.getBOAPI().updateByBindId("BO_EU_CPQ_PRODUCTION_PROCESS", bo.getBindId(), "SFTJ", "");
//					if (bms.isEmpty()) {
//						bms = "'" + bms + "'";
//					} else {
//						bms += ",'" + bms + "'";
//					}
				}
				/**
				 * 1、获取需要更新的制造件和装配件信息
				 */
				Map<String, JSONObject> comtMap=RefreshDataUtils.wageRateRefreshAssembly‌(userMap);
				/**
				 * 2、获取需要更新的模块信息
				 * 
				 */
				Map<String, Map<String, Object>> modulLists=RefreshModulDataUtils.wageRate‌RefreshModule(comtMap);
				/**
				 * 3、获取需要更新的项目报价记录台账中类型为模板的数据
				 * 
				 */			
				RefreshTempDataUtils.updateTempByWageRate‌(modulLists);
			}
		} catch (Exception e) {
			throw  e;
		}
		
	}

}
